import { defineConfig,loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import autoprefixer from 'autoprefixer';
import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
// import legacyPlugin  from '@vitejs/plugin-legacy';
import postCssPxToRem from 'postcss-pxtorem';
import path from 'path';
// https://vitejs.dev/config/
// const env = loadEnv(mode, process.cwd());

export default defineConfig({
		plugins: [vue(),Components({
			resolvers:[
				AntDesignVueResolver()
			]
		})],
		css: {
			postcss: {
				plugins: [
					autoprefixer({
						overrideBrowserslist: ['Android 4.1', 'iOS 7.1', 'Chrome > 31', 'ff > 31', 'ie >= 8'],
					}),
					postCssPxToRem({
						// 自适应，px>rem转换
						// 96
						rootValue: 144, // 75表示750设计稿，37.5表示375设计稿
						propList: ['*'], // 需要转换的属性，这里选择全部都进行转换
						selectorBlackList: ['norem'], // 过滤掉norem-开头的class，不进行rem转换
					}),
				],
			},
			preprocessorOptions:{
				less:{
					javascriptEnabled: true,
					additionalData:  `@import "${path.resolve(__dirname, 'src/assets/less/variable.less')}";`
				}
			}
		},
		base: "./",
		resolve: {
			alias: {
				'@': path.resolve(__dirname, 'src'),
			},
		},
		server: {
			host: '0.0.0.0',
			port: 1212,
			// proxy: {
			// 	'/api': {
			// 		target: 'http://192.168.1.3:8081',
			// 		// target: env.VITE_BASE_URL,
			// 		ws: true,
			// 		changeOrigin: true,
			// 		rewrite: (path) => path.replace(/^\/api/, ''),
			// 	},
			// }
		},
	})
	// }